#!/usr/bin/env python
# coding=utf-8

def calc(n):
    ans = 0
    n = str(n)
    for i in n:
        ans += int(i)
    return ans

ans = 0;

for i in range(1, 100):
    for j in range(1, 100):
        temp = pow(i, j)
        temp_ans = calc(temp)
        if temp_ans > ans:
            ans = temp_ans
print(ans)
